package org.ztr.yanai.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.ztr.yanai.blog.entity.Tag;
import org.ztr.yanai.blog.mapper.TagMapper;
import org.ztr.yanai.blog.service.TagService;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/11/22 10:00
 * @Description: 标签服务实现类
 * @Version: 1.0
 */
@Service
public class TagServiceImpl implements TagService {

    private final TagMapper tagMapper;

    public TagServiceImpl(TagMapper tagMapper) {
        this.tagMapper = tagMapper;
    }

    @Override
    public boolean createTag(Tag tag) {
        return tagMapper.insert(tag) > 0;
    }

    @Override
    public boolean deleteTagById(Long id) {
        return tagMapper.deleteById(id) > 0;
    }

    @Override
    public Tag getTagById(Long id) {
        return tagMapper.selectById(id);
    }

    @Override
    public Page<Tag> listTagsByPage(int pageNum, int pageSize, QueryWrapper<Tag> wrapper) {
        Page<Tag> page = new Page<>(pageNum, pageSize);
        return tagMapper.selectPage(page, wrapper);
    }

    @Override
    public boolean updateTag(Tag tag) {
        return tagMapper.updateById(tag) > 0;
    }
}
